/**
 * Copyright (c) 2018-present, Chen Guodong
 * All rights reserved.
 *
 * @flow
 */


<template>
  <ul>
    <li v-for="(item, index) in formData" :key="index" style="marginBottom: 10px">
      <Select :ref="item.model" :data="item" v-if="item.type === 'select'"></Select>
      <InputForm :ref="item.model" :data="item" v-if="item.type === 'input'"></InputForm>
    </li>
    <button @click="submitForm">提交</button>
  </ul>
</template>

<script>
import formData from "../../mock/formData.js";
import Select from "./Select";
import InputForm from "./InputForm";

export default {
  data() {
    return {
      formData: {}
    };
  },
  methods: {
    submitForm() {
      const self = this;
      const f = this.formData;
      let data = {};
      let tArray = [];
      f.map(item => {
        let obj = {};
        let key = self.$refs[item.model][0].key;
        let value = self.$refs[item.model][0].result;
        let layers = item.layers;
        if (layers && layers.length > 0) {
          ['forms'].forEach(function(j){
            console.log('layer', j)
            tArray[j] = new Array();
            ['3'].forEach(function(k){
              tArray[j][k] = new Array();
            }) 
          })
          // for (var k = 0; k < i; k++) {
          //   //一维长度为i,i为变量，可以根据实际情况改变
          //   tArray[k] = new Array(); //声明二维，每一个一维数组里面的一个元素都是一个数组；
          //   for (var j = 0; j < p; j++) {
          //     //一维数组里面每个元素数组可以包含的数量p，p也是一个变量；
          //     tArray[k][j] = ""; //这里将变量初始化，我这边统一初始化为空，后面在用所需的值覆盖里面的值
          //   }
          // }
        }
      });
      // console.log("d", d);
    }
  },
  mounted() {
    this.formData = formData.list;
    let name = "forms[3][amount]";
  },
  components: {
    Select,
    InputForm
  }
};
</script>

<style lang='less' scoped>
@import "../../util/themt.less";

.select {
  background: #fff;
  display: flex;
  padding: 5px 10px;
  font-size: 14px;
  line-height: 26px;
}
.label {
  flex: 1;
  text-align: left;
}

.value {
  flex: 1;
  text-align: right;
}
.default {
  color: @gray;
}
</style>
